package cn.xiaolang.function.java_jvm;

import cn.xiaolang.common.utils.Monitor;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @author Dean
 * @date 2023/3/21
 */
public class MemObjAnalyze {
    private static Map<String, Object> data = new HashMap<>();

    static class BlockObj {

        private Object content;

        public BlockObj(Object content) {
            this.content = content;
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Monitor.printlnMemory("before");

        MemObjAnalyze a = new MemObjAnalyze();
        for (int i = 0; i < 12; i++) {
            // 一个对象占10M，方便在GC日志中看出是否被回收
            data.put("A"+i,new BlockObj(Monitor.MB * 10));
        }
        System.out.println(data.size());
        Monitor.printlnMemory("after");

        TimeUnit.SECONDS.sleep(1800);
    }
}
